/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.form;

import com.hitechbangla.fctu.base.GameScene;
import java.awt.Dialog;
import java.util.List;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Sultan
 */
public class AddMapListPanel extends JDialog {

     private GameScene gameScene;
     private JList mapJlist;
     
    public AddMapListPanel(GameScene gameScene) {
        
        this.gameScene = gameScene;
        mapJlist = new JList();
        //mapJlist.setVisibleRowCount(5);
        mapJlist.setSelectionMode(
                ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        //add(new JScrollPane(mapJlist));
        //drawMapButton = new JButton("DrawMap");
        mapJlist.setSelectionModel(new DefaultListSelectionModel() {
            @Override
            public void setSelectionInterval(int index0, int index1) {
                if (isSelectedIndex(index0)) {
                    super.removeSelectionInterval(index0, index1);
                } else {
                    super.addSelectionInterval(index0, index1);
                }
            }
        });// end of setSelectionModel
        
        
            setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
            initComponents();
            setAlwaysOnTop(true);
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jListMap = new javax.swing.JList();
        jButtonDrawMap = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setType(java.awt.Window.Type.UTILITY);

        jListMap.setModel(new javax.swing.AbstractListModel() {
            String[] strings = gameScene.getMapStringArray();
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jListMap);

        jButtonDrawMap.setText("Draw Map");
        jButtonDrawMap.setName(""); // NOI18N
        jButtonDrawMap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDrawMapActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jButtonDrawMap)))
                .addContainerGap(51, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonDrawMap)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonDrawMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDrawMapActionPerformed
        // TODO add your handling code here:
        int[] lst = jListMap.getSelectedIndices();
         for(int i : lst){
            //Integer integer = (Integer)i;
            gameScene.selectedMapIndices.add(i);
            ////System.out.println("list element " + i.toString());
        }
        gameScene.HTBParent.repaint();
        
	//ameScene.HTBParent.repaint();
        this.setVisible(false);
	this.dispose();
        //System.out.println("size of selected index is " + gameScene.selectedMapIndices.size());
    }//GEN-LAST:event_jButtonDrawMapActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
       
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddMapListPanel(null).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonDrawMap;
    private javax.swing.JList jListMap;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
